Skip to content

testing/ostest: Add a test of the current directory. - #4062

Draft
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fb-cwd-kernel-test-up
Draft

casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fb-cwd-kernel-test-up

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

depends-on: apache/nuttx/pull/21907

Summary

Add a test of the current directory to ostest, cwd_test() in testing/ostest/cwd.c. The current directory is an attribute of the task group. The test checks that getcwd() gives the directory of chdir(), that setenv() and unsetenv() of PWD do not change it, that chdir() in a thread changes it for the task group, that getcwd() gives the new name after rename() of the directory, and that getcwd() fails with ENOENT after rmdir() of the directory, also when a new directory of the same name appears.

The test checks apache/nuttx#21907 ("fs: Keep the current directory in the task group."). Merge this PR after it, and after #4061 (NSH sets PWD).

Impact

Only ostest. The test uses directories of the pseudo file system (/ostest_cwd, /ostest_cwd2), so it needs no mounted file system. It is built when CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set (Make and CMake). The thread case needs pthreads, the PWD cases the environment. At the end the test goes back to its directory and PWD, and removes its directories.

Testing

QEMU with HVF, ostest with this test:

Configuration nuttx master 46066440966 with apache/nuttx#21907 (and #4061)
qemu-armv8a:knsh (kernel build) 4 errors: setenv PWD, unsetenv PWD, rename, rmdir; ostest asserts cwd_test: PASS, ostest exits with status 0
qemu-armv8a:nsh (flat build) the same 4 errors; ostest asserts cwd_test: PASS, ostest exits with status 0

The thread case passes on master too: the threads of a task group already shared the directory through the environment. It stays as a guard.

tools/checkpatch.sh -c -u -m -g of nuttx passes on the commit.

The current directory is an attribute of the task group.  The test
checks that:

- getcwd() gives the directory of chdir();
- setenv() and unsetenv() of PWD do not change it;
- chdir() in a thread changes it for the task group;
- after rename() of the directory, getcwd() gives the new name;
- after rmdir() of the directory, getcwd() fails with ENOENT, also
  when a new directory of the same name appears.

The test uses directories of the pseudo file system, so it needs no
mounted file system.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants